<?php
/**
 * Text element
 *
 */
class ArrowFormCheckboxGroup extends ArrowFormField{
	
	
	public function configure(){
		parent::configure();	
		$this->addProperties(array(
			"columns" => 2,
			"labelField" => false,
		));
	}	
	
	public function validate( $proposedValue ){
		return true;
	}
	
	public function generateOutput(){
		$attribuites = array();
		$attribuites["name"] = $this->getHtmlName()."[]";
		
		$str =  '<table><tr>';
		$value = $this->getValue();
		if(is_string($value))
			$value = explode("|", $value);
		$content = $this->getContent();
		if($content){
			
			$labelField = $this->getProperty("labelField");		
			$i = 0;
			foreach( $content as $key => $text ){
				if(is_object($text))
					$text = $text[$labelField];
				
				
				$attribuites["id"] = "arrow-checkbox-".$this->getName()."-".$key;
				$attribuites["value"] = $key;
				if( $i % $this->getProperty("columns") == 0 ) $str .= "</tr><tr>" ;
				
				$checked = ($value && in_array($key,$value))?'checked="checked"':'';
				$str.= '<td><input type="checkbox" '.$this->genTagsFromArray($attribuites).''.$checked.' '.$this->addExternal().'/></td>';
				$str.= '<td><label for="'.$attribuites["id"].'">'.$text.'</label></td>';
				
			 	++$i;
			}
		}

		return $str."</tr></table>";
	}


}
?>